Dashboard Temp Share Shortlinks Frames API

HTMLify

Majority Element - II.cpp(CN)
Views: 1 | Author: cody
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
#include <bits/stdc++.h>

vector<int> majorityElementII(vector<int> &arr)
{
    // Write your code here.
    map<int, int>mpp;
    vector<int>v;
    int n = arr.size();
    for(int i =0; i<n; i++){
        mpp[arr[i]]++;
    }

    for(auto it : mpp){
        if(it.second > n/3){
            v.push_back(it.first);
        }
    }
    return v;

}